﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3


ToolBar{
    property point point: Qt.point(x,y)
    property bool isSmallWindow: false
    background: Rectangle
    {
        color:"#00000000"
    }

    width:parent.width
    Layout.fillWidth: true
    RowLayout{

        anchors.fill: parent
        MusicToolButton{
           iconSource: "qrc:/images/music"
           toolTip:"音乐"
           onClicked: {
               aboutPop.open()
           }
        }
        MusicToolButton{
           iconSource: "qrc:/images/about"
           toolTip:"关于"
           onClicked: {
               Qt.openUrlExternally("https://www.baidu.com")
           }
        }
        MusicToolButton{
            id:smallwindow
           iconSource: "qrc:/images/small-window"
           toolTip:"小窗播放"
           visible: !isSmallWindow
           onClicked: {
               setWindowSize(330,650)
               pageHomeView.visible = false
               pageDetailView.visible = true
               isSmallWindow = true

           }
        }
        MusicToolButton{
            id:normalwindow
           iconSource: "qrc:/images/exit-small-window"
           toolTip:"退出窗口播放"
           visible: isSmallWindow
           onClicked: {
               setWindowSize()
               isSmallWindow = false

           }
        }
        Item{
            Layout.fillWidth: true
            height:32
            Text {
                anchors.centerIn: parent
                text: qsTr("音乐播放器")
                font.family: "微软雅黑"
                font.pointSize: 15
                color:"#ffffff"
            }
            MouseArea{
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                onPressed: {
                    point = Qt.point(mouseX,mouseY)

                }
                onMouseXChanged: {
                    var x = window.x + mouseX - point.x
                    if(x<-(window.width - 70)) x = -(window.width -70)
                    if(x>Screen.destopAvailableWidth - 70) x = Screen.destopAvailableWidth -70
                    window.x  = x
                }
                onMouseYChanged: {
                    var y = window.y +mouseY - point.y
                    if(y<=0) y = 0
                    if(y>Screen.destopAvailableHeight - 70) y = Screen.destopAvailableHeight -70
                    window.y  = y
                }
            }
        }
        MusicToolButton{
           iconSource: "qrc:/images/minimize-screen"
           toolTip:"最小化"
           onClicked: {
               window.hide()
           }
        }
        MusicToolButton{
        id:resize
           iconSource: "qrc:/images/small-screen"
           toolTip:"退出全屏"
           visible: false
           onClicked: {
               setWindowSize()
               window.visibility = Window.AutomaticVisibility
               maxWindow.visible = true
               resize.visible = false
           }
        }
        MusicIconButton{
            id:maxWindow
               iconSource: "qrc:/images/full-screen"
               toolTip:"全屏"
               onClicked: {
                   window.visibility = Window.Maximized
                   maxWindow.visible = false
                   resize.visible = true
               }
        }

        MusicToolButton{
           iconSource: "qrc:/images/power"
           toolTip:"退出"
           onClicked: {
               Qt.quit()
           }
        }
    }
    Popup{
        id:aboutPop

        topInset: 0
        leftInset:-2
        rightInset: 0
        bottomInset: 0

        parent:Overlay.overlay
        x:(parent.width - width)/2
        y:(parent.height - height)/2
        width: 250
        height: 230

        background: Rectangle{
            color:"#e9f4ff"
            radius: 5
            border.color: "#2273a7ab"
        }
        contentItem: ColumnLayout{
            width:parent.width
            height: parent.height
            Layout.alignment: Qt.AlignCenter
            Image{
                Layout.preferredHeight: 60
                Layout.fillWidth: true
                source: "qrc:/images/music"
                fillMode: Image.PreserveAspectFit
            }
            Text{
                text: qsTr("音乐播放器")
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 18
                color: "#8573a7ab"
                font.family: "微软雅黑"
                font.bold: true
            }
            Text{
                text: qsTr("这是我的cloud music player")
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 16
                color: "#8573a7ab"
                font.family: "微软雅黑"
                font.bold: true
            }
            Text{
                text: qsTr("www.baidu.com")
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 18
                color: "#8573a7ab"
                font.family: "微软雅黑"
                font.bold: true
            }
        }
    }

    function setWindowSize(width=window.mWINDOW_WIDTH,height=mWINDOW_HEIGHT)
    {
        window.height =height
        window.width = width
        window.x=(Screen.destroyAvailabelWidth - window.width) /2
        window.y=(Screen.destroyAvailabelWidth - window.height) /2
    }


}
